﻿@model WarOfDev.Web.ViewModels.UserViewModel
@{
    ViewBag.Title = "Edit";
}
<h2>
    Edit</h2>
@Html.ActionLink("roles", "GetAllRoles", new { roles = Model == null ? string.Empty : Model.Roles, groupId = Model == null ? string.Empty : Model.GroupId })
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>User</legend>
        @Html.HiddenFor(model => model.Id)
        @Html.HiddenFor(model => model.UserId)
        <div class="editor-label">
            @Html.LabelFor(model => model.UserName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.UserName)
            @Html.ValidationMessageFor(model => model.UserName)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Password)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Password)
            @Html.ValidationMessageFor(model => model.Password)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Description)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Description)
            @Html.ValidationMessageFor(model => model.Description)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.IsLocked)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.IsLocked)
            @Html.ValidationMessageFor(model => model.IsLocked)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.GroupId)
        </div>
        <div class="editor-field">
            @Html.Action("GetAllGroups", "Role", new { id = Model.GroupId })
            @Html.ValidationMessageFor(model => model.GroupId)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Roles)
            @Html.ValidationMessageFor(model => model.IsLocked)
        </div>
        <div class="editor-field">
            <div id="roleList">
                @Html.Action("GetAllRoles", new { roles = Model.Roles, groupId = Model.GroupId })
            </div>
        </div>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}
<div>
    @Html.ActionLink("Back to List", "Index")
</div>
<script type="text/javascript">

    $("#GroupId").change(function () {
        var groupId = $(this).val();

        $.ajax({
            url: '/User/GetAllRoles?roles=@(Model == null ? string.Empty : Model.Roles)&groupId=' + groupId,
            success: function (data) {
                $("#roleList").html(data);
            },
            error: function (e) {
                alert();
            }
        });
    });
</script>
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
